﻿Imports System.Data.OleDb

Public Class AddCommentCricketGround
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
   
    Function getSuffix(ByVal fn As String)
        Dim fileParts = fn.Split(".")
        Dim suffix = fileParts(fileParts.Length - 1)
        Return "." & suffix
    End Function

    Protected Sub btnSaveCommentOnCricketGround_Click(sender As Object, e As EventArgs) Handles btnSaveCommentOnCricketGround.Click
        Dim newFileName As String
        newFileName = Guid.NewGuid().ToString() & getSuffix(fuProfilePicture.FileName)
        If fuProfilePicture.HasFile Then
            fuProfilePicture.SaveAs(Server.MapPath("~/Pictures/Grounds") & "/" & newFileName)
        End If

        Dim p1 As New OleDbParameter("@f1", Request.QueryString("ID"))
        Dim p2 As New OleDbParameter("@f2", "Pictures/Grounds" & "/" & newFileName)
        Dim p3 As New OleDbParameter("@f3", txtTitle.Text)
        Dim p4 As New OleDbParameter("@f4", txtDescription.Text)
        Dim p5 As New OleDbParameter("@f5", User.Identity.Name)
        Dim p6 As New OleDbParameter("@f6", Format(Date.Now(), "dd/MM/yyyy hh:mm:ss tt"))
        Dim sql As String = "insert into CricketGroundComments(GroundID,GroundPicture,Title,UserComments,CreatedBy,CreatedDate) values (@f1,@f2,@f3,@4,@f5,@f6)"
        DataAccessLayer.ExecuteNonQuery(sql, p1, p2, p3, p4, p5, p6)

        Dim sql2 As String = "Update userprofile set PostedComments= PostedComments+1 where username =@f5 "
        DataAccessLayer.ExecuteNonQuery(sql2, p5)
        Response.Redirect("~/CricGroundDetails.aspx?ID=" + Request.QueryString("ID"))
    End Sub
End Class